home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / examples / Fergusonppc.d < prev    next >
Text File  |  2002-10-28  |  2KB  |  65 lines

  1. // Ferguson.d - example of how to generate ferguson's kubics (curves) in D
  2.  
  3. OPT    PPC
  4.  
  5. MODULE    'intuition/intuition',
  6.             'utility/tagitem'
  7.  
  8. /*
  9.     rp            - window rastport
  10.     xA,yA        - coordinates of point A
  11.     xa,ya        - vector in point A
  12.     xB,yB        - coordinates of point B
  13.     xb,yb        - vector in point B
  14.     steps        - number of intersections
  15. */
  16. PROC Ferguson(rp,xA:FLOAT,yA:FLOAT,xa:FLOAT,ya:FLOAT,xB:FLOAT,yB:FLOAT,xb:FLOAT,yb:FLOAT,steps)
  17.     DEFF    delta,t,x,y,f0,f1,f2,f3
  18.     DEF    i
  19.     delta:=1.0/steps
  20.     SetAPen(rp,1)
  21.     x:=xA*20.0
  22.     y:=yA*-20.0
  23.     Move(rp,x+160,y+160)
  24. //    PrintF('$\z\h[8],$\z\h[8],$\z\h[8],$\z\h[8]\n',xA,yA,x,y)
  25.  
  26.     FOR i:=0 TO steps
  27.         t:=delta*i
  28.         f0:=2.0*t*t*t-3.0*t*t+1.0        // Ferguson's polynoms
  29.         f1:=-2.0*t*t*t+3.0*t*t
  30.         f2:=t*t*t-2.0*t*t+t
  31.         f3:=t*t*t-t*t
  32.         x:=xA*f0+xB*f1+xa*f2+xb*f3        // parametrical representations for x and y coords
  33.         y:=yA*f0+yB*f1+ya*f2+yb*f3
  34.         x*=20.0
  35.         y*=-20.0
  36.         Draw(rp,x+160,y+160)
  37. //        WritePixel(rp,x+160,y+160)
  38.     ENDFOR
  39.  
  40. ENDPROC
  41.  
  42. PROC main()
  43.     DEF w:PTR TO Window
  44.     IF w:=OpenWindowTags(NIL,
  45.             WA_InnerWidth,320,
  46.             WA_InnerHeight,320,
  47.             WA_IDCMP,IDCMP_CLOSEWINDOW,
  48.             WA_Flags,WFLG_DRAGBAR|WFLG_GIMMEZEROZERO|WFLG_RMBTRAP|WFLG_ACTIVATE|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET,
  49.             WA_Title,'Ferguson''s Cubic',
  50.             TAG_END)
  51.     
  52.         Ferguson(w.RPort,
  53.           -5.0,  0.0,  // position of point A
  54.          -10.0, 10.0,  // vector in point A
  55.            5.0,  0.0,  // position of point B
  56.          -10.0,-10.0,  // vector in point B
  57.           1000)            // # of intersections
  58.     
  59.         WaitPort(w.UserPort)
  60.         CloseWindow(w)
  61.     ENDIF
  62. ENDPROC
  63.  
  64. // MarK 7/8/99
  65.